///* 
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */

var shouldLoadMoreCandidates;

function iniciarPaginaViewSearch(){
    var x;
    x=$(document);
    x.ready(inicializarEventosViewSearch);
}


function reinitShouldLoadMoreCandidates(){
    shouldLoadMoreCandidates=true;
    //asignarMinHeight();
}

function inicializarEventosViewSearch(){
    //asignarMinHeight();
//    shouldLoadMoreCandidates=true;
    scroller=$("#facesForm\\:adquiredFacesPanel");
    botonera_scroller_anchor = scroller.offset().top;
    $(window).scroll(function(){
       fixAdquired(scroller,botonera_scroller_anchor);
//        if($(window).scrollTop() + $(window).height() > $(document).height() - 75) {
//            if(shouldLoadMoreCandidates){
//                shouldLoadMoreCandidates=false;
//                $("#facesForm\\:moreCandidatesLink").trigger('click');
//                var startTime = new Date().getTime();
//                while (new Date().getTime() < startTime + 100);
//            }
//        }
    });
    
}

function scrollImages(facesCount){
    $(".loadImages").find('img').batchImageLoad({
        loadingCompleteCallback: function(){
            $.scrollTo($(".facesColumn").get(facesCount));
        }
    });
}

function fixAdquired(scroller,botonera_scroller_anchor){
    if($(this).scrollTop() >= botonera_scroller_anchor && scroller.css('position') != 'fixed'){
            scroller.css({
                'position': 'fixed',
                'top': '0px',
                'z-index':'4'
            });
        }
    else if($(this).scrollTop() < botonera_scroller_anchor && scroller.css('position') != 'relative'){
            scroller.css({
                'position': 'relative'
            });
        }
}

function asignarMinHeight(){
    $(".loadImages").find('img').batchImageLoad({
        loadingCompleteCallback: function(){
            $(".imagenBusqueda").each(function(){
                $(this).parent().css('min-height',$(this).css('height'));
            });
        }
    });
}


function handleLoadStart(ext) {
    if(ext.direction == "down"){
        PF('waypointWidget').remove(); 
        loadMoreCandidates();
   }

} 

function handleLoadStop(loaded,maxperrow,maxcan) {
    if(loaded+maxperrow<maxcan){
        $(".loadImages").find('img').batchImageLoad({
            loadingCompleteCallback: function(){
                PF('waypointWidget').register();
            }
        });
    }
} 